#!/bin/bash

#CHOICE=$(echo -e "Enable Proxy\nDisable Proxy" | rofi -dmenu -p "Proxy Settings")
#
#case "$CHOICE" in
#"Enable Proxy")
#  /home/tom/.config/qutebrowser/toggle_proxy.sh
#  ;;
#"Disable Proxy")
#  /home/tom/.config/qutebrowser/toggle_proxy.sh
#  ;;
#*)
#  echo "No action taken"
#  ;;
#esac

CONFIG_FILE="$HOME/.config/qutebrowser/config.py"
PROXY_SETTING="config.set('content.proxy', 'http://192.168.50.10:1082/')"

# 函数：获取当前代理状态
get_proxy_state() {
  if grep -q "^$PROXY_SETTING" "$CONFIG_FILE"; then
    echo "Enabled"
  elif grep -q "^# $PROXY_SETTING" "$CONFIG_FILE"; then
    echo "Disabled"
  else
    echo "Not Configured"
  fi
}

# 显示 Rofi 菜单
CHOICE=$(echo -e "Enable Proxy\nDisable Proxy\nCurrent Status: $(get_proxy_state)" | rofi -dmenu -p "Proxy Settings")

# 根据用户选择执行操作
case "$CHOICE" in
"Enable Proxy")
  /home/tom/.config/qutebrowser/toggle_proxy.sh

  notify-send "Proxy Status" "Proxy is now $(get_proxy_state)"
  ;;
"Disable Proxy")
  /home/tom/.config/qutebrowser/toggle_proxy.sh
  notify-send "Proxy Status" "Proxy is now $(get_proxy_state)"
  ;;
*)
  echo "No action taken"
  ;;
esac
